package com.ljy.service.impl;

import com.ljy.constant.JwtClaimsConstant;
import com.ljy.dto.EmpLoginDTO;
import com.ljy.entity.Employee;
import com.ljy.mapper.EmpMapper;
import com.ljy.properties.JwtProperties;
import com.ljy.service.EmpService;
import com.ljy.utills.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    EmpMapper empMapper;
    @Autowired
    JwtProperties jwtProperties;
    @Override
    public String login(EmpLoginDTO dto) {
        Employee emp = empMapper.getEmp(dto);
        if(emp!=null){
            Map<String,Object> claims=new HashMap<>();
            claims.put(JwtClaimsConstant.EMP_ID,emp.getId());
            String jwt = JwtUtil.createJWT(jwtProperties.getAdminSecretKey(), jwtProperties.getAdminTtl(), claims);
            return jwt;
        }


        return null;
    }
}
